#include <iostream>
#include <vector>
#include <algorithm>

bool trace_what(std::vector<unsigned int> &vctNums)
{
    //bool ret{false};
    // auto finder = std::find_if(vctNums.rbegin(), vctNums.rend(), [](unsigned int n){
    //     return n == 0;
    // });
    // if (finder == vctNums.rend())
    // {
    //     return true;
    // }

    bool zeroFlag{false};
    int need{0};
    for (int i = vctNums.size() - 2; i >= 0; --i)
    {
        if (!zeroFlag && vctNums[i] == 0)
        {
            zeroFlag = true;
            need = 0;
            continue;
        }

        if (zeroFlag)
        {
            ++need;
            if (vctNums[i] > need)
            {
                zeroFlag = false;
                need = 0;
            }
        }
    }

    return !zeroFlag;
}
int main()
{
    bool bret = false;
    std::vector<unsigned int> arr1{2, 3, 1, 1, 4};  // 1
    std::vector<unsigned int> arr2{0, 3, 1, 1, 4};  // 0
    std::vector<unsigned int> arr3{2, 3, 1, 1, 0};  // 1
    std::vector<unsigned int> arr4{3, 2, 1, 0, 4};  // 0
    std::vector<unsigned int> arr5{2, 2, 0, 0, 4};  // 0
    std::vector<unsigned int> arr6{1, 3, 0, 0, 0};  // 1

    std::cout << trace_what(arr1) << std::endl;
    std::cout << trace_what(arr2) << std::endl;
    std::cout << trace_what(arr3) << std::endl;
    std::cout << trace_what(arr4) << std::endl;
    std::cout << trace_what(arr5) << std::endl;
    std::cout << trace_what(arr6) << std::endl;

    return 0;
}